import numpy as np
import matplotlib.pyplot as plt
from irlab.basics.radar_equation import RadarEquation as RE

# Parameters
pt = 1.5e+6  # peak power in Watts
freq = 5.6e+9  # radar operating frequency in Hz
g = 45.0  # antenna gain in dB
sigma = 0.1  # radar cross section in m squared
te = 290.0  # effective noise temperature in Kelvins
b = 5.0e+6  # radar operating bandwidth in Hz
nf = 3.0  # noise figure in dB
loss = 6.0  # radar losses in dB
range_ = np.linspace(25e3, 165e3, 1000)  # target range 25 - 165 Km, 1000 points
rangekm = range_ / 1000  # convert range to kilometers

# Calculate SNR for different peak powers
snr1 = RE.radar_equation(pt, freq, g, sigma, te, b, nf, loss, range_)
snr2 = RE.radar_equation(pt * 0.4, freq, g, sigma, te, b, nf, loss, range_)
snr3 = RE.radar_equation(pt * 1.8, freq, g, sigma, te, b, nf, loss, range_)

# Plot SNR versus range for different peak powers
plt.figure(1)
plt.plot(rangekm, snr3, 'k-', label='Pt = 2.16 MW')
plt.plot(rangekm, snr1, 'k--', label='Pt = 1.5 MW')
plt.plot(rangekm, snr2, 'k:', label='Pt = 0.6 MW')
plt.grid()
plt.legend()
plt.xlabel('Detection range - Km')
plt.ylabel('SNR - dB')
plt.title('SNR versus Range for Different Peak Powers')
plt.show()